﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Kyers._50kweb.BaseEntity;
using Kyers._50kweb.CoreData;
using System.Data;

namespace Kyers._50kweb.EntityData.User
{
    public partial class UserEntity :BaseEntity.BaseEntity
    {
       
       public static int Insert(object Entity)
       {
           return InsertObject(Entity, UserTable);
       }
       public static int Update(object Entity)
       {
           return UpdateObject(Entity, UserTable);
       }
       public static void Delete(int Id)
       {
           DeleteObject(Id, UserTable);
       }

       /// <summary>
       /// Update with custom condition
       /// </summary>
       /// <param name="Entity"></param>
       /// <param name="Table"></param>
       /// <param name="Condition"></param>
       /// <returns></returns>
       public static  int UpdateCustom(object Entity, string Condition = "")
       {
           return UpdateCustomObject(Entity, UserTable, Condition);
       }

       /// <summary>
       /// Get All Data
       /// </summary>
       /// <param name="Table"></param>
       /// <returns></returns>
       public static  DataTable GetAll()
       {
           return GetAllObject(UserTable);
       }

       /// <summary>
       /// Get By ID
       /// </summary>
       /// <param name="Id"></param>
       /// <param name="Table"></param>
       /// <returns></returns>
       public static  DataTable GetByID(int Id)
       {
           return GetObjectByID(Id, UserTable);
       }

       /// <summary>
       /// Get By GuidID
       /// </summary>
       /// <param name="GuidID"></param>
       /// <param name="Table"></param>
       /// <returns></returns>
       public static  DataTable GetByGuidID(Guid GuidID)
       {
           return GetObjectByGuidID(GuidID, UserTable);
       }
       /// <summary>
       /// Get By Field Name
       /// </summary>
       /// <param name="FieldName"></param>
       /// <param name="FieldNameValue"></param>
       /// <param name="Table"></param>
       /// <returns></returns>
       public static  DataTable GetByFieldName(string FieldName, object FieldNameValue)
       {
           string where = "";
           if (FieldNameValue.GetType() == typeof(int))
           {
               where += FieldName + "=" + int.Parse(FieldNameValue.ToString());
           }
           if (FieldNameValue.GetType() == typeof(string))
           {
               where += FieldName + "='" + FieldNameValue.ToString() + "'";
           }
           if (FieldNameValue.GetType() == typeof(decimal))
           {
               where += FieldName + "=" + decimal.Parse(FieldNameValue.ToString());
           }
           if (FieldNameValue.GetType() == typeof(double))
           {
               where += FieldName + "=" + double.Parse(FieldNameValue.ToString());
           }
           if (FieldNameValue.GetType() == typeof(DateTime))
           {
               where += FieldName + "='" + DateTime.Parse(FieldNameValue.ToString()) + "'";
           }
           if (FieldNameValue.GetType() == typeof(float))
           {
               where += FieldName + "=" + float.Parse(FieldNameValue.ToString());
           }
           return GetObjectByFieldName(FieldName, FieldNameValue, UserTable);
       }

       /// <summary>
       /// Get by custom sql command
       /// </summary>
       /// <param name="sql"></param>
       /// <returns></returns>
       public static  DataTable GetByCustomSQL(string sql)
       {
           return GetObjectByCustomSQL(sql);
       }
    }
}
